package server;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

import java.io.IOException;

/**
 * Created by lecity123 on 17/1/4.
 */

public class HttpServerService extends Service {

    private HttpServer mHttpServer = null;//这个是HttpServer的句柄。


    @Override
    public void onCreate() {
        //在这里开启HTTP Server。
        mHttpServer = new HttpServer(8080);
        try {
            mHttpServer.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onDestroy() {
        //在这里关闭HTTP Server
        if (mHttpServer != null)
            mHttpServer.stop();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i("DemoLog", "TestService -> onStartCommand, startId: " + startId + ", Thread ID: " + Thread.currentThread().getId());
        return START_STICKY;
    }


    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}